package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOPeration {
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入要删除的书的书名:");
        String name = scanner.nextLine();
        int index = -1;
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book2 = bookList.getBook(i);
            if (book2.getBookName().equals(name)) {
                index = i;
                break;
            }

        }
        if (index == -1) {
            System.out.println("没有你想要删除的书");
            return;
        }
        for (int i = index; i < currentSize - 1; i++) {
                //booList[j] = booList[j+1];
                Book book = bookList.getBook(i+1);
                bookList.setBooks(i,book);
        }
        bookList.setBooks(currentSize - 1,null);
        bookList.setUsedSize(currentSize - 1);
        System.out.println("删除成功");
    }
}
